package com.miyu.book.utils.magic;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class GetBeanUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext context) {
        GetBeanUtil .applicationContext = context;
    }

    public static Object getBeanByName(String name) {
        return applicationContext.getBean(name);
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
    public static <T> T getBeanByClass(Class<T> c){
        return applicationContext.getBean(c);
    }
}
